$(function () {
    var qrcode = new QRCode(document.getElementById("qrcode"), {
        width : 200,
        height : 200
    });

    $.ajax({
        url:'/pay/wxpay/createqccode/'+$("#orderId").text(),
        dataType:'json',
        success:function (result) {
            console.log(result);
            if(result.code==200) {
                makeCode(result.data.codeUrl);
                //检查订单是否支付成功
                alert(result.data.codeUrl);
                queryorderstatus(result.data.order_no);
            } else {
                alert('生成二维码异常');
            }
        }
    })
    function queryorderstatus(order_no) {
        setInterval(function () {
            $.ajax({
                url:'/pay/wxpay/queryorderstatus/' + order_no,
                dataType:'json',
                success:function (result) {
                    if(result.data.status==2) {
                        alert('支付成功');
                        location.href = '/home';
                    }
                },
                error:function (xhr) {
                    console.log(xhr);
                }
            })
        },2000);
    }
    function makeCode (url) {
        qrcode.makeCode(url);
    }
})
